package org.jadestudio.dsdown.dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.jadestudio.dsdown.entity.ManageAdminLogin;
import org.jadestudio.dsdown.entity.ManageGame;
import org.jadestudio.dsdown.entity.ManageGameDownloads;
import org.jadestudio.dsdown.entity.ManageGamePic;
import org.jadestudio.dsdown.entity.ManageGamePublishCompany;
import org.jadestudio.dsdown.entity.ManageGamePurchase;
import org.jadestudio.dsdown.entity.ManageHomePagePicCfg;
import org.springframework.stereotype.Component;

import com.ibatis.sqlmap.client.SqlMapClient;

@Component
public class GameManageDao {
	
	@Resource
	private SqlMapClient sqlMapClient;
	private ManageAdminLogin manageAdmin;
	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	
	/**
	 * 发行厂商插入
	 * @return
	 * @throws SQLException 
	 */
	public void publishCompanyAdd(ManageGamePublishCompany manageGamePublishCompany) throws SQLException{
		 sqlMapClient.insert("test.publishCompanyAdd",manageGamePublishCompany);
	}
	
	/**
	 * 发行厂商修改
	 * @return
	 * @throws SQLException 
	 */
	public int publishCompanyModify(ManageGamePublishCompany manageGamePublishCompany) throws SQLException{
		 return sqlMapClient.update("test.publishCompanyModify",manageGamePublishCompany);
	}
	
	/**
	 * 发行厂商查询
	 * @return
	 * @throws SQLException 
	 */
	public List publishCompanyQuery(Map queryMap) throws SQLException{
		 return sqlMapClient.queryForList("test.publishCompanyQuery",queryMap);
	}
	
	/**
	 * 发行厂商个数查询
	 * @return
	 * @throws SQLException 
	 */
	public int publishCompanyCountQuery(Map queryMap) throws SQLException{
		 return Integer.valueOf(sqlMapClient.queryForObject("test.publishCompanyCountQuery",queryMap).toString());
	}
	
	/**
	 * 发行厂商查询ById
	 * @return
	 * @throws SQLException 
	 */
	public Map publishCompanyQueryById(String id) throws SQLException{
		 return (Map)sqlMapClient.queryForObject("test.publishCompanyQueryById",id);
	}
	
	/**
	 * 发行厂商删除
	 * @return
	 * @throws SQLException 
	 */
	public int publishCompanyDeleteById(String id) throws SQLException{
		 return sqlMapClient.delete("test.publishCompanyDeleteById",id);
	}
	
	/**
	 * 游戏类型查询
	 * @return
	 * @throws SQLException
	 */
	public List gameTypeQuery() throws SQLException{
		return sqlMapClient.queryForList("test.gameTypeQuery");
	}
	
	/**
	 * 游戏平台查询
	 * @return
	 * @throws SQLException
	 */
	public List gamePlatFormQuery() throws SQLException{
		return sqlMapClient.queryForList("test.gamePlatFormQuery");
	}
	
	/**
	 *  模糊查询游戏发行厂商
	 * @param gamePublishCompanyName
	 * @return
	 * @throws SQLException
	 */
	public List gamePublishCompanyQuery(String gamePublishCompanyName)throws SQLException{
		return sqlMapClient.queryForList("test.gamePublishCompanyQueryByName",gamePublishCompanyName);
	}
	
	/**
	 * 插入图鉴
	 * @param manageGame
	 * @throws SQLException
	 */
	public void gameInsert(ManageGame manageGame) throws SQLException{
		 sqlMapClient.insert("test.insertGame",manageGame);
	}
	
	/**
	 * 更新图鉴
	 * @param manageGame
	 * @throws SQLException
	 */
	public void gameModify(ManageGame manageGame) throws SQLException{
		 sqlMapClient.update("test.updateGame",manageGame);
	}
	
	/**
	 * 插入图鉴下载地址
	 * @param manageGameDownloads
	 * @throws SQLException
	 */
	public void gameDownloadsInsert(ManageGameDownloads manageGameDownloads) throws SQLException{
		 sqlMapClient.insert("test.insertGameDownloads",manageGameDownloads);
	}
	
	/**
	 * 图鉴下载地址更新
	 * @param manageGameDownloads
	 * @throws SQLException
	 */
	public void gameDownloadsUpdate(ManageGameDownloads manageGameDownloads) throws SQLException{
		 sqlMapClient.update("test.updateGameDownloads",manageGameDownloads);
	}
	
	/**
	 * 图鉴下载地址删除
	 * @param manageGameDownloads
	 * @throws SQLException
	 */
	public void gameDownloadsDelete(String gameId) throws SQLException{
		 sqlMapClient.delete("test.deleteGameDownloads",gameId);
	}
	
	
	/**
	 * 插入图鉴购买地址
	 * @param manageGamePurchase
	 * @throws SQLException
	 */
	public void gamePurchaseInsert(ManageGamePurchase manageGamePurchase) throws SQLException{
		 sqlMapClient.insert("test.insertGamePurchase",manageGamePurchase);
	}
	
	/**
	 * 更新图鉴购买地址
	 * @param manageGamePurchase
	 * @throws SQLException
	 */
	public void gamePurchaseUpdate(ManageGamePurchase manageGamePurchase) throws SQLException{
		 sqlMapClient.update("test.updateGamePurchase",manageGamePurchase);
	}
	
	/**
	 * 图鉴购买地址删除
	 * @param manageGameDownloads
	 * @throws SQLException
	 */
	public void gamePurchaseDelete(String gameId) throws SQLException{
		 sqlMapClient.delete("test.deleteGamePurchase",gameId);
	}
	
	/**
	 * 插入图鉴图片地址
	 * @param manageGamePurchase
	 * @throws SQLException
	 */
	public void gamePicInsert(ManageGamePic manageGamePic) throws SQLException{
		 sqlMapClient.insert("test.insertGamePic",manageGamePic);
	}
	
	/**
	 * 更新图鉴图片地址
	 * @param manageGamePurchase
	 * @throws SQLException
	 */
	public void gamePicUpdate(ManageGamePic manageGamePic) throws SQLException{
		 sqlMapClient.update("test.updateGamePic",manageGamePic);
	}
	
	/**
	 * 图鉴图片地址删除
	 * @param manageGameDownloads
	 * @throws SQLException
	 */
	public void gamePicDelete(String gameId) throws SQLException{
		 sqlMapClient.delete("test.deleteGamePic",gameId);
	}
	
	/**
	 * 图鉴查询
	 * @return
	 * @throws SQLException 
	 */
	public List gameQuery(Map queryMap) throws SQLException{
		 return sqlMapClient.queryForList("test.gameQuery",queryMap);
	}
	
	/**
	 * 图鉴查询BYID
	 * @return
	 * @throws SQLException 
	 */
	public Map gameQueryById(String id) throws SQLException{
		 return (Map) sqlMapClient.queryForObject("test.gameQueryById",id);
	}
	
	/**
	 * 图鉴删除ById
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public int gameDelete(String id)throws SQLException{
		/*删除game本身*/
		Integer deleteFlag=(Integer)sqlMapClient.queryForObject("test.gameDeleteById",id);
		if(deleteFlag>0){
			/*删除游戏下载地址*/
			this.gameDownloadsDelete(id);
			/*删除图鉴购买地址*/
			this.gamePurchaseDelete(id);
			/*删除图片地址*/
			this.gamePicDelete(id);
		}
		return 1;
	}
	
	/**
	 * 图鉴下载地址查询BYGameId
	 * @param id
	 * @return
	 */
	public List gameDownloadsQueryByGameId(String gameId){
		try {
			return (List) sqlMapClient.queryForList("test.gameDownloadsQueryByGameId",gameId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 图鉴购买地址查询BYGameId
	 * @param id
	 * @return
	 */
	public List gamePurchaseQueryByGameId(String gameId){
		try {
			return (List) sqlMapClient.queryForList("test.gamePurchaseQueryByGameId",gameId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 图鉴图片上传地址查询BYGameId
	 * @param id
	 * @return
	 */
	public List gamePicQueryByGameId(String gameId){
		try {
			return (List) sqlMapClient.queryForList("test.gamePicQueryByGameId",gameId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 图鉴数量查询 
	 * @param queryMap
	 * @return
	 * @throws SQLException
	 */
	public int gameCountQuery(Map queryMap) throws SQLException{
		 return Integer.valueOf(sqlMapClient.queryForObject("test.gameCountQuery",queryMap).toString());
	}
	
	
	/**
	 * 主页大图配置查询
	 * @param queryMap
	 * @return
	 * @throws SQLException
	 */
	public List<Map> homePagePicCfgQuery() throws SQLException{
		 return sqlMapClient.queryForList("test.homePagePicCfgQuery");
	}
	
	/**
	 * 主页大图记录更新
	 * @param queryMap
	 * @return
	 * @throws SQLException
	 */
	public void homePagePicCfgInsert(ManageHomePagePicCfg homePagePicCfg) throws SQLException{
		sqlMapClient.insert("test.homePagePicCfgInsert",homePagePicCfg);
	}
	
	/**
	 * 主页大图记录删除
	 * @throws Exception
	 */
	public void homePagePicCfgDelete() throws Exception{
		sqlMapClient.delete("test.homePagePicCfgDelete");
	}
	
	
	/**
	 * 服务器参数查询
	 */
	public List<Map> serverCfgQuery() throws SQLException{
		 return sqlMapClient.queryForList("test.serverCfgQuery");
	}
	
	/**
	 * 服务器参数更新
	 */
	public int serverCfgUpdate(Map map) throws SQLException{
		 return sqlMapClient.update("test.serverCfgUpdate",map);
	}
	
	

	
	
	
	
}
